package cn.ym.mongodb.service.impl;

import cn.ym.mongodb.dao.CommentRepository;
import cn.ym.mongodb.domain.Comment;

import cn.ym.mongodb.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class  CommentServiceImpl implements CommentService {

    @Autowired
    private CommentRepository commentRepository;

    @Override
    public void add(Comment comment){
        commentRepository.save(comment); //id存在就是修改，不存在就是添加
    }

    @Override
    public void update(Comment comment) {
        commentRepository.save(comment); //id存在就是修改，不存在就是添加
    }

    @Override
    public void delete(String id) {
        commentRepository.deleteById(id);
    }

    @Override
    public Comment findOne(String id) {
        return commentRepository.findById(id).get();
    }

    @Override
    public List<Comment> findAll() {
        return commentRepository.findAll();
    }

    @Override
    public List<Comment> findByArticleId(Long articleId) {
        return commentRepository.findByArticleId(articleId);

    }


}